#define _USE_MATH_DEFINES

# include<iostream>
# include<cmath>
# include"EquationSolver.h"

using namespace::std;

/**
* @brief 把方程 x=tan x 的求解问题转为求解函数 y=x-tan x 的零点的问题
* 
*/
class func : public Function
{
public:
    double operator()(double _x)
    {
        return (_x - tan(_x));
    }
};

/**
* @brief 主函数
* 
*/
int main()
{
    cout << "Solution for Qustion C: " << endl;
    cout << "Test the Newton's method." << endl;
    func f;

    // 寻找 4.5 附近的根
    Newton Solver1(4.5, 0.00000001, 10, f);
    double x1 = Solver1.solve();
    double y1 = f(x1);
    cout << "Test for function: the appropriate root near 4.5 is " << x1 << " , and f(x1)= " << y1 << endl;

    // 寻找 7.7 附近的根
    Newton Solver2(7.7, 0.00000001, 10, f);
    double x2 = Solver2.solve();
    double y2 = f(x2);
    cout << "Test for function: the appropriate root near 7.7 is " << x2 << " , and f(x2)= " << y2 << endl;

    cout << "" << endl;

    return 0;
}